package vip.housir.kotlindemo.controller

import org.springframework.web.bind.annotation.*
import vip.housir.kotlindemo.entity.User
import vip.housir.kotlindemo.service.UserService
import javax.annotation.Resource


@RestController
class UserController {

    @Resource
    lateinit var userService: UserService

    @RequestMapping(value = ["/get"])
    fun getUserById(@RequestParam(value = "id") id: Long): User? {
        return userService.findUserById(id)
    }

    @RequestMapping(value = ["/create"])
    fun createUser(@RequestBody user: User): User {
        user.hate = listOf(1, 2, 3, 4)
        userService.createUser(user)
        return user
    }


    @RequestMapping(value = ["/update"])
    fun updateUser(@RequestBody user: User): User {
        userService.updateUser(user)
        return user
    }

    @RequestMapping(value = ["/delete"])
    fun removeUserById(@RequestParam(value = "id") id: Long): Int {
        return userService.deleteUserById(id)
    }
}
